let url = location.href
let id = splitStrToObject(url).h
let num_x
// 页面初始化
function chushi() {
    if (id == 29) {
        $('.nav>ul>li:nth-child(2)').addClass('active')
        num_x = 7
        $('#selected>span').html('9.9专区')
    }
    if (id == 170) {
        $('.nav>ul>li:nth-child(3)').addClass('active')
        num_x = 174
        $('#selected>span').html('超值大额卷')
    }
    if (id == 3183) {
        $('.nav>ul>li:nth-child(4)').addClass('active')
        num_x = 3183
        $('#selected>span').html('降温急救穿搭')
    }
}
chushi()
//首页栏目数据
function banner_ajax() {
    $.ajax({
        type: 'get',
        url: `http://www.xiongmaoyouxuan.com/api/column/${id}`,
        success: function (data) { //响应的参数
            if (id == 3183) {
                lanmu(data.data)
            } else {
                lanmu(data.data.subColumns)
            }
        }
    })
}
banner_ajax()
//栏目
function lanmu(list) {
    if (id == 3183) {
        $('#sort').html(`<span>${list.name}</span>`)
        $('#sort>span:nth-child(1)').addClass('active')
        span_x()
    } else {
        let strS = ``
        let str1 = list.map(function (itme) {
            return `<span>${itme.name}</span>`
        })
        strS += str1.join('')
        $('#sort').html(strS)
        $('#sort>span:nth-child(1)').addClass('active')
        span_x()
    }
}

//商品列表数据
function list_ajax() {
    if (id == 3183) {
        $.ajax({
            type: 'get',
            url: `http://www.xiongmaoyouxuan.com/api/column/3183/items?start=0`,
            data: {
                start: 20
            },
            success: function (data) { //响应的参数
                list(data.data.list)
            }
        })
    } else {
        $.ajax({
            type: 'get',
            url: `http://www.xiongmaoyouxuan.com/api/sub_column/${num_x}/items`,
            data: {
                start: 0
            },
            success: function (data) { //响应的参数
                console.log(data);
                list(data.data.list)
            }
        })
    }
}
list_ajax()

//更多商品列表数据
function moreAjax(num) {
    if (id == 3183) {
        $.ajax({
            type: 'get',
            url: `http://www.xiongmaoyouxuan.com/api/column/3183/items?start=0`,
            data: {
                start: num * 40
            },
            success: function (data) { //响应的参数
                console.log(data);
                list_more(data.data.list)
            }
        })
    } else {
        $.ajax({
            type: 'get',
            url: `http://www.xiongmaoyouxuan.com/api/sub_column/${num_x}/items`,
            data: {
                start: num * 20
            },
            success: function (data) { //响应的参数
                list_more(data.data.list)
            }
        })
    }
}
//点击加载更多
function btn_more() {
    let s = 0
    $('#morebtn>.btn').click(function () {
        s++
        moreAjax(s)
    })
}
btn_more()


